/**************************************************************************
*Copyright (C) 2025 公司名, Inc.(Gmbh) or its affiliates.
*
*All Rights Reserved.
*
*@file bsp_key.h
*
*@par dependencies
* - stdio.h
* - stdint.h
* - cmsis_os2.h
*
*@author fhc | 部门 | 公司 
*
*@brief Provide the HAL APIs of Key and corresponding options.
*
*Processing flow:
*
*call directly.
*
*@version V1.0 2025-11-06
*
*@note 1 tab == 2 spaces!
*
**************************************************************************/

#ifndef __BSP_KEY_H__
#define __BSP_KEY_H__

//******************************** Includes *********************************//

#include <stdio.h>                  // the compiling lib.
#include <stdint.h>

#include "cmsis_os2.h"              // os
#include "FreeRTOS.h"
#include "queue.h"                  

#include "stm32f4xx_hal.h"          // drive/core
#include "gpio.h"

//******************************** Includes *********************************//

//******************************** Defines **********************************//
extern osThreadId_t g_key_TaskHandle;
extern QueueHandle_t g_key_queue;        /* the queue of th key                */
extern const osThreadAttr_t g_key_Task_attributes;

typedef enum
{
	KEY_OK                = 0,           /* Operation completed successfully.  */
	KEY_ERROR             = 1,           /* Run-time error without case matched*/
	KEY_ERRORTIMEOUT      = 2,           /* Operation failed with timeout      */
	KEY_ERRORRESOURCE     = 3,           /* Resource not available.            */
	KEY_ERRORPARAMETER    = 4,           /* Parameter error.                   */
	KEY_ERRORNOMEMORY     = 5,           /* Out of memory.                     */
	KEY_ERRORISR          = 6,           /* Not allowed in ISR context         */
	KEY_RESERVED          = 0x7FFFFFFF   /* Reserved                           */
} key_status_t;

typedef enum
{
	KEY_PRESS             = 0,			 /* the key is pressed				   */	
	KEY_NOT_PRESS		  = 1,           /* the key isn't pressed   		   */
	KEY_SHORT_PRESS		  = 2,			 /* the key is short pressed   		   */
	KEY_LONG_PRESS		  = 3,			 /* the key is long pressed   		   */  
	KEY_PRESS_RESERVED	  = 0xff	     /* Reserved  		                   */             
} key_press_status_t;

//******************************** Defines **********************************//


//******************************** Declaring ********************************//

/**
 * @brief scan the key status .
 * 
 * Steps:
 *  1.doing the specific operations
 *  
 * @param[in] key_val   :the pointer to the status of the key  
 * 
 * @return key_status_t : Status of the function.
 * 
 * */
key_status_t key_scan(key_press_status_t* const key_val);
/**
 * @brief key_task_func for thread to run.
 * 
 * Steps:
 *  1.doing the specific operations
 *  
 * @param[in] void 
 * 
 * @return void.
 * 
 * */
void key_task_func(void *argument);

/**
 * @brief Determine whether the button is pressed briefly or held down for a 
 * 		  long time .
 * 
 * Steps:
 *  1.doing the specific operations
 *  
 * @param[in] key_val   : the pointer to the status of the key  
 * @param[in] key_val   : Long press time 
 * 
 * @return key_status_t : Status of the function.
 * 
 * */
key_status_t key_long_short_scan(key_press_status_t* const key_val,
								const uint32_t time_interval );
//******************************** Declaring ********************************//
#endif // !__BSP_KEY_H__


